<div class="list-body">
	<form id="app-search-form">
	<div class="row">
		<div class="search-input">
        	<input type="text"  id="app-name-input" placeholder="输入应用平台名称" onblur="Trim(this,this.value)" >
          <input type="text" name="name" id="appNameDisNone" style="display: none;"> <!--删？ -->
         {{#if roleinfo.role}}
         	<input type="text" id="app-uname-input" placeholder="输入用户名称" onblur="Trim(this,this.value)" >
          <input type="text" name="uname" id="uNameDisNone" style="display: none;"> <!--删？ -->
         {{/if}}
    	<div style="display: none;">
          <input type="text" name="pageCurrent" value="1">
          <input type="text" name="pageSize" value="12">
      </div>
        	  <button type="button" onclick="app_submit_btn()" class="search-btn" data-icon="search"></button>
  	</div>
    
    	<a class="add-btn app-btn" onclick="dialog_app_add()"><i class="fa fa-plus-square-o"></i><span>添加应用平台</span></a>
	</div>

	<ul class="row app-list-content list-content"></ul>
  </form>

	<div id="pagination_app" style="text-align: center; display: none;"></div>
</div>
  
<script type="text/javascript">
$(function(){
     var appTotalNum ;
    pagination_callback(1,12,1);
    if('{{roleinfo.role}}'){     //管理员禁用
      $('.app-btn').addClass('disable');
      $('.app-btn').removeAttr('onclick');
    }else{
      $('.app-btn').removeClass('disable');
      $('.app-btn').attr('onclick');
    }
    $("input").placeholder();
})

function app_submit_btn(){
      $('#app-name-input').val()!='输入应用平台名称' ? $('#appNameDisNone').val($('#app-name-input').val()) : $('#appNameDisNone').val('');
      if('{{roleinfo.role}}'){
        $('#app-uname-input').val()!='输入用户名称' ? $('#uNameDisNone').val($('#app-uname-input').val()) : $('#uNameDisNone').val('');
      }
      BJUI.ajax('ajaxform', {
          url: '/app/list',
          form: $.CurrentNavtab.find('#app-search-form'),
          validate: false,
          okalert:false,
          loadingmask: true,
          okCallback: function(json, options) {
          	$('#pagination_app').pagination('destroy')     //删？
          	$('#pagination_app').pagination({
      	   	 	total:json.totalRow, pageSize:12, callback:pagination_callback
      		})
          	appTotalNum =json.totalRow;
            set_list(json);
            if(json.totalRow<=12){
                $("#pagination_app").css("display","none");
              }else{
                $("#pagination_app").css("display","block");
              }
            }
        })
	   }

function pagination_callback(pageCurrent, pageSize,num) {
      var names=$("#appNameDisNone").val(); // //取出存进的参数值
      var unames=$("#uNameDisNone").val(); // //取出存进的参数值
        BJUI.ajax('doajax', {
              url: '/app/list',
              okalert:false,
              loadingmask: true,
              data: {pageCurrent:pageCurrent, pageSize:pageSize,name:names,uname:unames},
              okCallback: function(json, options) {
                  set_list(json);
                  if(num==1){
                         $('#pagination_app').pagination({
                        total:json.totalRow, pageSize:12, callback:pagination_callback
                    }) 
                  }
                 appTotalNum =json.totalRow;
                  if(json.totalRow>pageSize){
                    $("#pagination_app").css("display","block");
                  }else{
                    $("#pagination_app").css("display","none");
                  }
               }
            })
          }
  
function set_list(json){
   $('.app-list-content').empty();
    var btnArr=[
        {title:"编辑",icon:"fa fa-edit",fun:"app_edit"},
        {title:"详情",icon:"fa fa-list-alt",fun:"app_details"},
        {title:"删除",icon:"fa fa-trash-o",fun:"app_del"},
      ];
    $('.app-list-content').setList(json.list,btnArr,'fa-th-large');
   
    }

function dialog_app_add(){
    	BJUI.dialog({
      		id:"appAdd",
      		url:"/app/editPage",
      		title:"添加应用平台",
          type:"post",
      		width:"620",
          height:"620",
      		mask:true,
          maxable:false
      })
   }
function app_details(obj){
  var id=$(obj).parent().parent().prevAll("#item-id").text();
    BJUI.dialog({
      id:"appDetails",
      url:"/app/details",
      title:"应用",
      type:"post",
      data:{"id":id},
      width:"620",
      height:"600",
      mask:true,
      maxable:false
    })
}
function app_edit(obj){

        var id=$(obj).parent().parent().prevAll("#item-id").text();
        var userid=$(obj).parent().parent().prevAll("#user-id").text();

        BJUI.dialog({
               id:"appEdit",
               url:"/app/editPage",
               title:"编辑应用",
               type:"post",
               data:{"id":id,"userid":userid},
               width:"620",
               height:"600",
               mask:true,
               maxable:false
        }) 
}
       
function app_del(obj){
      var id=$(obj).parent().parent().prevAll("#item-id").text();
	    BJUI.alertmsg('confirm', '确定要删除吗！', {
          okCall: function() { //点击确定时运行
    		     BJUI.ajax('doajax',{
    		           url:"/app/del",
    		           type:"post",
    		           dataType:"json",
    		           data:{"id":id},
                   loadingmask: true,
                    okCallback: function(json, options) {
                      
                           appTotalNum -=1;
                $('#pagination_app').pagination('destroy')
                $('#pagination_app').pagination({
            total:appTotalNum, pageSize:12, callback:pagination_callback
        });
                       pagination_callback(1,12,1);
                    }
    		      })
           }
        })
	    }
</script>

